package com.cy.server.controller;


import com.cy.server.dto.DepartmentDto;
import com.cy.server.pojo.Department;
import com.cy.server.pojo.RespBean;
import com.cy.server.service.IDepartmentService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LiShaoZhuo
 * @since 2021-04-26
 */
@RestController
@RequestMapping("/system/basic/department")
public class DepartmentController {

    @Autowired
    IDepartmentService departmentService;

    @ApiOperation("部门信息分页")
    @PostMapping("/list")
    public RespBean selectAllDepartments(@RequestBody DepartmentDto departmentDto){
        PageInfo<Department> pageInfo = departmentService.selectAllDepartments(departmentDto);
        return RespBean.success(pageInfo);
    }

    @ApiOperation("查询所有部门")
    @GetMapping("/select")
    public List<Department> getAllDepartments(){
        return departmentService.getAllDepartments();
    }

    @ApiOperation("新增部门")
    @PostMapping("/add")
    public RespBean addDepartment(@RequestBody Department department){
        return departmentService.addDepartment(department);
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/delete/{id}")
    public RespBean deleteDepartment(@PathVariable Integer id){
        return departmentService.deleteDepartment(id);
    }
}
